package com.cn.crmsystem.controller.approveController;
import com.cn.crmsystem.pojo.*;
import com.cn.crmsystem.service.approveService.TravelService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;

@Controller
@Api(value = "出差test",tags = "出差API")
public class TravelController {
	@Autowired TravelService travelService;
	//添加
    @RequestMapping(value = "/TravelInsert",name = "添加出差",method = RequestMethod.POST)
		@ApiOperation(value = "出差添加",notes = "插入",httpMethod = "POST", response = String.class)
	@ResponseBody
public ResultJson TravelInsert(@RequestBody
								   @ApiParam(name = "添加",value = "插入",required = false)	Approve AP){
		ResultJson resultJson=new ResultJson();
		Integer leader=AP.getLeader_Id();
		Travel  travel=AP.getTravel();
		resultJson=travelService.TravelInsert(travel,leader);
        return  resultJson;
}
//更新
@RequestMapping(value = "/TravelUpdate",name = "更新出差",method = RequestMethod.POST)
@ApiOperation(value = "出差更新",notes = "状态更新",httpMethod = "POST", response = String.class)
@ApiImplicitParams({
		@ApiImplicitParam(name = "appid",value = "审核id",paramType = "query",dataType = "Integer",required = false),
		@ApiImplicitParam(name = "state",value = "状态",paramType = "query",dataType = "Integer",required = false)
})
@ResponseBody
public  ResultJson TravelUpdate(@RequestParam(name = "appid") Integer appid,
								@RequestParam(name = "state") Integer state){
	ResultJson resultJson=new ResultJson();
	resultJson=travelService.UpdateTravel(appid,state);
    return  resultJson;
}
//查询审核人
	@RequestMapping(value = "/selectTravelLeader",name = "出差查询审核人",method = RequestMethod.POST)
	@ApiOperation(value = "查询审核人",notes = "查询领导",httpMethod = "POST", response = String.class)
	@ResponseBody
	public  ResultJson selectTravelLeader(
	 ){
	Integer userid=2;
		ResultJson resultJson=new ResultJson();
		resultJson=travelService.selectLeader(userid);
		return  resultJson;
	}
//查询出差列表
	@RequestMapping(value = "/selectTravel",name = "查询出差列表",method = RequestMethod.POST)
	@ApiOperation(value = "出差查询",notes = "查询出差列表",httpMethod = "POST", response = String.class)
	@ResponseBody
		public  ResultJson selectTravel() {
				Integer method=0;
		ResultJson resultJson=new ResultJson();
		Login login = new Login();
		login.setUser_id(2);
		Integer userid=login.getUser_id();
		resultJson=travelService.SelectMyTravel(userid,method);
		return  resultJson;
	}
	//删除
	@RequestMapping(value = "/DeleteTravelLeader",name = "删除出差",method = RequestMethod.POST)
	@ApiOperation(value = "出差删除",notes = "更改deleteid",httpMethod = "POST", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userid",value = "审核id",paramType = "query",dataType = "Integer",required = false)
	})
	@ResponseBody
	public  ResultJson DeleteTravelLeader (@RequestParam(name = "userid") Integer appid) {
		ResultJson resultJson = new ResultJson();
		resultJson=travelService.DeleteTravel(appid);
		return  resultJson;
	}
	//条件查询
	@RequestMapping(value = "/SelectConditionTravel",name = "出差条件查询",method = RequestMethod.POST)
	@ApiOperation(value = "审核状态切换",notes = "条件查询",httpMethod = "POST", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userid",value = "用户id",paramType = "query",dataType = "Integer",required = false),
			@ApiImplicitParam(name = "method",value = "我发出的还是我审核",paramType = "query",dataType = "String",required = false),
			@ApiImplicitParam(name = "state",value = "审核状态",paramType = "query",dataType = "Integer",required = false)
	})
	@ResponseBody
	public  ResultJson SelectConditionTravel(@RequestParam(name = "userid") Integer userid,
													@RequestParam(name = "method") String method,
													@RequestParam(name = "state") String state ){
		ResultJson resultJson=new ResultJson();
		resultJson=travelService.SelectConditionTravel(userid,method,state);
		return resultJson;
	}
}
